package com.alibaba.sdk.config.async;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * ttl加载配置文件的配置
 *
 * @ author  Shawn(Shawn_0217@163.com)
 * @ date    2021/4/27 15:42
 * @ company Alibaba
 */
@Configuration
public class TtlAsyncConfiguration {

    /**
     * 获取 TtlThreadPoolConfig
     *
     * @return
     */
    @Bean({"ttl"})
    public ThreadPoolConfig getTtlAsyncThreadPoolConfig() {
        return new ThreadPoolConfig();
    }

    /**
     * 创建ttl任务执行器
     *
     * @param config
     * @return
     */
    @Bean({"ttlTaskExecutor"})
    public ThreadPoolTaskExecutor ttlTaskExecutor(@Qualifier("ttl")ThreadPoolConfig config) {
        return ExecutorFactory.createPoolTaskExecutor(config);
    }
}
